#include "Tools/ToolCopyObject.h"

using namespace Ogre;
ToolCopyObject::ToolCopyObject(Ogre::Camera *mCam, Ogre::SceneManager *mScMgr, RaySceneQuery* ray)
{

	mCamera = mCam;
	moveCam = new ActionMoveCamera(mCam);
	select = new ActionSelectObject(mCam,mScMgr,ray);

	altPressed=false;
	objectSelected=false;
}

ToolCopyObject::~ToolCopyObject(){
	//destroy objects and queries
}

void ToolCopyObject::updateGraphics(const FrameEvent &evt){

	moveCam->updateGraphics(evt);
	if(objectSelected)
		moveObject->updateGraphics(evt);
}

void ToolCopyObject::mouseMoved(const OIS::MouseEvent &evt){

	if(objectSelected){
		moveObject->mouseMoved(evt);
		scale->mouseMoved(evt);
	}
	moveCam->mouseMoved(evt);
}

void ToolCopyObject::mousePressed(const OIS::MouseEvent &evt){
	

	if(!objectSelected){
		if(select->mousePressed(evt)){

			moveObject=select->getActionMoveObject();
			scale = new ActionScaleObject(select->getSelectedNode());
			select->getSelectedNode()->showBoundingBox(true);
			objectSelected=true;
		}
	}
	/*
	if(!altPressed && objectSelected){
		moveObject->mousePressed(evt);
		MapEditor::instance()->toolEnded();
	}
	else if(!objectSelected){
		if(select->mousePressed(evt)){
			moveObject=select->getActionMoveObject();
			scale = new ActionScaleObject(select->getSelectedNode());
			select->getSelectedNode()->showBoundingBox(true);
		}
	}
	else{
		//Hacer la copia
	}
	*/
}

void ToolCopyObject::keyPressed(const OIS::KeyEvent &evt){
	
	if(evt.key==OIS::KC_LMENU)
		altPressed=true;
	moveCam->keyPressed(evt);
}
void ToolCopyObject::keyReleased(const OIS::KeyEvent &e){
	
	if(e.key==OIS::KC_LMENU)
		altPressed=false;
	moveCam->keyReleased(e);
}

SceneNode* ToolCopyObject::createNode(){

	SceneNode *node;

	std::string nodeName="SNode"+Constants::instance()->getNum();
	Entity *ent = mCamera->getSceneManager()->createEntity(nodeName, objectName);

	node = mCamera->getSceneManager()->getRootSceneNode()->createChildSceneNode(nodeName);
	node->attachObject(ent);
	node->showBoundingBox(true);
	return node;

}
